package www.dianbaozu.com.ui.chat.chat.adapter

import android.graphics.Color
import android.view.View
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import com.netease.nim.uikit.databinding.ItemMsgBinding
import com.zhengsr.tablib.view.adapter.TabFlowAdapter
import www.dianbaozu.com.R
import www.wen.com.common.lib.data.entities.ChatTabEntity
import www.wen.com.common.lib.extension.dp
import www.wen.com.common.lib.extension.getColorAgency
import www.wen.com.common.lib.extension.unread

class ChatTabFlowAdapter(layoutId:Int, data: List<ChatTabEntity>): TabFlowAdapter<ChatTabEntity>(layoutId,data) {
    private var binding: ItemMsgBinding? = null

    override fun bindView(view: View, data: ChatTabEntity, position: Int) {
        binding = DataBindingUtil.bind(view)
        binding?.apply {
            itemText.text = data.title
            tvUnreadMessage.text = data.unreadCount.unread()
            slUnreadMessage.isVisible = data.unreadCount > 0
            if (data.unreadCount > 0){
                itemText.setPadding(12.dp(),6.dp(),2.dp(),6.dp())
            }else{
                itemText.setPadding(12.dp(),6.dp(),12.dp(),6.dp())
            }
        }

    }

    override fun onItemSelectState(view: View, isSelected: Boolean) {
        super.onItemSelectState(view, isSelected)
        setTextColor(
            view,
            R.id.item_text,
            if (isSelected) Color.WHITE else getColorAgency(R.color.color999999)
        )
    }
}